<template name="lmBottom">
	<view class="goodBtm">
		<text class="stockNull" v-if="resouceData.stock < 1">课程已售罄啦~</text>
		<view class="goodOp">
			<view class="item" @tap="zixun">
				<text class="iconfont icon-message"></text>
				<text>咨询</text>
			</view>
			<view class="shareBox" @tap="share">
				<text class="iconfont icon-B"></text>
				<block v-if="isLogin && userInfo.code && resouceData.courseAgent && (resouceData.courseAgent.income1 || resouceData.courseAgent.income2)">
					<text class="red">赚￥{{ yongjin }}</text>
				</block>
				<block v-else><text>分享</text></block>
			</view>

			<view class="fenxiaoBox" v-if="resouceData.courseAgent && fxPrice">
				<text class="zhuan">赚</text>
				<text class="fxPrice">￥{{ fxPrice }}</text>
			</view>

			<!-- <view class="item" @tap="toPage" :data-id="shopInfo.id" data-url="shopDetail">
				<text class="iconfont icon-shoucangdianjia"></text>
				<text>店铺</text>
			</view> -->
			<!-- #ifndef H5 -->
			<!-- <view class="item" @tap="guanzhu">
				<text class="iconfont" :class="[goodData.fav==1?'icon-likefill':'icon-like']"></text>
				<text>{{goodData.fav==1?'已关注':'关注'}}</text>
			</view> -->
			<!-- #endif -->
			<view class="btnBox2" v-if="isLogin && userInfo.code && discountPrice">
				<!-- #ifdef H5 -->
				<a id="toApp" href="javascript:;" data-url="zeroDetail" onclick="toApp()" :data-id="resouceData.id"></a>
				<!-- #endif -->
				<button @tap="buy" :disabled="resouceData.stock < 1">
					<text>￥{{ resouceData.price }}立即抢购</text>
					<text>(赚￥{{ yongjin }})</text>
				</button>
			</view>
			<view class="btnBox" v-else>
				<!-- #ifdef H5 -->
				<a id="toApp" href="javascript:;" data-url="zeroDetail" onclick="toApp()" :data-id="resouceData.id"></a>
				<!-- #endif -->

				<button id="jinzhi" @tap="buy" :disabled="resouceData.stock < 1">￥{{ resouceData.price }} 立即抢购</button>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapGetters, mapMutation, mapActions } from 'vuex';
import COMM from '@/common/common.js';
export default {
	computed: {
		...mapState({
			userInfo: state => state.user.userInfo,
			isLogin: state => state.user.isLogin
		})
	},
	name: 'lmBottom', //组件名称
	// 传递参数
	props: {
		resouceData: {
			type: Object,
			default: () => {
				return {
					leftSeconds: 1,
					course: {
						id: 0
					},
					stock: 1
				};
			}
		},
		// goodData:{
		// 	type:Object,
		// 	default:()=>{
		// 		return null
		// 	}
		// },
		lmActive: {
			type: Object,
			default: null
		},
		gettime: '',
		endTime: '',
		actId: 0,
		canGroup: 0,
		discountPrice:0
	},
	// 组件参数
	data() {
		return {
			shopInfo: {},
			goodData: {},
			fxPrice: 0,
			yongjin: 0,
			getstatus: 0,
			groupId: 0,
			orderNo: '',
			acId: 0
		};
	},
	watch: {
		resouceData(newVal) {
			this.getCircle();
			// this.checkXieYi();
		}
	},
	// 组件方法
	methods: {
		share() {
			this.$parent.showPoster();
		},
		getCircle() {
			if (this.discountPrice) {
				// if (this.resouceData.courseAgent.income1) {
					
				// } else {
				// 	this.yongjin = this.resouceData.courseAgent.income2;
				// }
				this.yongjin = this.discountPrice
			}

			this.$store
				.dispatch('apiGetShopDetail', {
					id: this.resouceData.storeId ? this.resouceData.storeId : this.resouceData.store.id,
					userId: 0
				})
				.then(res => {
					let ssq = COMM.getSSQByAreaId(res.data.data.areaId);
					if (res.data.data.streetId) {
						this.$store.dispatch('apiGetBusCircle', res.data.data.areaId).then(circleRes => {
							circleRes.data.data.forEach((x, i) => {
								if (x.id == res.data.data.streetId) {
									this.diqu = x.name;
								}
							});
						});
					} else {
						this.diqu = ssq[2];
					}
				});
		},

		getFxPrice() {
			if (this.resouceData.courseAgent && this.resouceData.courseAgent.amount2 > this.resouceData.courseAgent.amount1) {
				this.fxPrice = this.resouceData.courseAgent.amount2;
			} else {
				this.fxPrice = this.resouceData.courseAgent.amount1;
			}
		},
		zixun() {
			let _this = this;
			if (this.isLogin) {
				uni.showLoading({
					title: '',
					mask: false
				});

				let toImid = _this.shopInfo.imid;
				if (getApp().globalData.TIM_SDK_READY) {
					uni.hideLoading();
					_this.toPage({
						url: 'conversationDt',
						cvid: 'C2C' + toImid,
						toImId: toImid
					});
				} else {
					_this.$store.dispatch('timLogin', _this.userInfo.imid).then(res => {
						setTimeout(() => {
							uni.hideLoading();
							_this.toPage({
								url: 'conversationDt',
								cvid: 'C2C' + toImid,
								toImId: toImid
							});
						}, 1000);
					});
				}
			} else {
				// this.toPage('login');
				this.$parent.open();
			}
		},
		lmbuy() {
			if (this.isLogin) {
				this.$store
					.dispatch('apiGetGroupDetailpt', {
						id: this.resouceData.courseGroup.id,
						userId: this.isLogin ? this.userInfo.userId : 0
					})
					.then(res => {
						this.groupId = res.data.data.groupId;
						this.orderNo = res.data.data.orderNo[0]? res.data.data.orderNo[0].orderNo:'';						
						this.acId = res.data.data.id;
						this.refund = res.data.data.amount1;
						if (this.groupId) {
							//有进行中的拼团
							this.$store
								.dispatch('apiGetListStatus', {
									groupId: this.groupId,
									userId:this.userInfo.userId
								})
								.then(res => {
									this.getstatus = res.data.order.status;
									
									if (this.getstatus == 3) {
										
										this.toPage({
											url: 'pay',
											id: this.orderNo
										});
									} else {
										this.toPage({
											url: 'myGroupDetaillm',
											id: this.groupId,
											actId: this.actId
										});
									}
								});

							
						} else {
							let cfmArr = [this.resouceData];
							uni.setStorage({
								key: 'confirmList',
								data: cfmArr,
								complete: () => {
									this.toPage({
										url: 'confirmOrder',
										actId: this.actId,
										acId: res.data.data.id,
										isGroup: 1,
										refund: res.data.data.amount1
										// isLm:1
									});
								}
							});
						}
					});
			} else {
				if (this.resouceData.groupStatus == 1) {
					//有进行中的拼团
					// this.toPage({
					// 	url: 'login'
					// });
					this.$parent.open();
				} else {
					let cfmArr = [this.resouceData];
					uni.setStorage({
						key: 'confirmList',
						data: cfmArr,
						complete: () => {
							
							this.$parent.open();
							// this.toPage({
							// 	url: 'login'
							// });
						}
					});
				}
			}
		},
		buy() {
			let _now = new Date();
			var _kaishi = new Date(this.gettime.replace(/-/g, '/'));
			var _end = new Date(this.endTime.replace(/-/g, '/'));
			var _zhanshiTime = _kaishi.getTime() - _now.getTime();
			var _endTime = _end.getTime() - _now.getTime();
			uni.setStorageSync('orderNo', 'asdasd');
			if (_zhanshiTime > 0) {
				uni.showModal({
					title: '友情提示',
					content: '活动暂未开放，敬请期待！',
					success: function(res) {
						if (res.confirm) {
						} else if (res.cancel) {
						}
					}
				});
			} else if (_endTime <= 0) {
				uni.showModal({
					title: '友情提示',
					content: '该活动已结束！',
					success: function(res) {
						if (res.confirm) {
						} else if (res.cancel) {
						}
					}
				});
			} else if (this.isLogin) {
				if (this.canGroup == 1) {
					//正确的是1，下一版改回来
					this.lmbuy();
				} else {
					let cfmArr = [this.resouceData];
					uni.setStorage({
						key: 'confirmList',
						data: cfmArr,
						complete: () => {
							this.toPage({
								url: 'confirmOrder',
								actId: this.actId,
								isLm: 1
							});
						}
					});
				}
			} else {
				if (this.canGroup == 1) {
					//正确的是1，下一版改回来
					this.lmbuy();
				} else {
					let cfmArr = [this.resouceData];
					uni.setStorage({
						key: 'confirmList',
						data: cfmArr,
						complete: () => {
							// this.toPage({
							// 	url: 'login',
							// 	to: 'confirmOrder',
							// 	actId: this.actId,
							// 	isLm: 1
							// });
							this.$parent.open();
						}
					});
				}
			}
		}
	},
	created() {
		// setTimeout(() => {
		// 	// this.getDjs()
		// 	this.getCircle();
		// }, 500);
	}
};
</script>

<style lang="less">
.goodBtm {
	position: fixed;
	width: 100%;
	height: 180upx;
	bottom: 0;
	left: 0;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	z-index: 2;

	.priceBox {
		height: 75upx;
		display: flex;
		align-items: center;
		background-color: #f8e4a9;
		padding: 0 50upx;

		.iconfont {
			font-size: 40upx;
			color: #ff3b2b;
			margin-right: 16upx;
		}

		text {
			font-size: 32upx;
			color: #a17f68;
		}

		.yyPrice {
			color: #ff3b2b;
			font-size: 38upx;
			flex: 1;
		}

		.zaifu {
			color: #a17f68;
			font-size: 38upx;
		}
	}

	.stockNull {
		background-color: #333333;
		color: #ffffff;
		line-height: 75upx;
		text-align: center;
		font-size: 28upx;
	}

	.goodOp {
		box-sizing: border-box;
		height: 105upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;
		padding: 0 0 0 38upx;
		border-top: 1px solid #b5bac2;

		.item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			text {
				color: #6b6b6b;
				font-size: 20upx;
			}

			.iconfont {
				font-size: 48upx;
				color: #2c2c2c;
			}
			.icon-likefill {
				color: #ffcd11;
			}
		}
		.fenxiaoBox {
			display: flex;
			align-items: baseline;
			.zhuan {
				font-size: 32upx;
			}
			.fxPrice {
				font-size: 40upx;
				color: #ff2727;
				font-weight: bold;
			}
		}
		.btnBox {
			display: flex;
			height: 105upx;
			position: relative;
			.pintuan {
				background: linear-gradient(to right, #f8c527, #ff6902);
			}

			button {
				padding: 0 40upx;
				width: 350upx;
				border: none;
				margin: 0;
				outline: none;
				height: 105upx;
				line-height: 105upx;
				font-size: 32upx;
				color: #ffffff;
				font-weight: bold;
				border-radius: 0upx;
				background: linear-gradient(to right, #fe5828, #fe305b);
			}

			button[disabled='true'] {
				color: #eeeeee;
			}

			a {
				text-decoration: none;
				position: absolute;
				display: block;
				width: 100%;
				height: 100%;
				z-index: 555;
				top: 0;
				left: 0;
			}
		}
		.btnBox2 {
			height: 105upx;
			justify-content: flex-end;
			position: relative;

			button {
				width: 350upx;
				border: none;
				margin: 0;
				outline: none;
				height: 105upx;
				font-size: 32upx;
				color: #ffffff;
				font-weight: bold;
				padding: 0;
				border-radius: 0;
				background: linear-gradient(to right, #ffc300, #ff9503);
			}

			button:after {
				border: none;
				outline: none;
			}
			button:first-child {
				line-height: 105upx;
			}
			button:last-child {
				background: linear-gradient(to right, #fe5828, #fe305b);
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				text {
					margin: 0;
					line-height: 36upx;
				}
				text:last-child {
					line-height: 24upx;
					font-size: 24upx;
					font-weight: normal;
				}
			}

			button[disabled='true'] {
				color: #eeeeee;
			}

			a {
				text-decoration: none;
				position: absolute;
				display: block;
				width: 100%;
				height: 100%;
				z-index: 555;
				top: 0;
				left: 0;
			}
		}
	}
}
.shareBox {
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	// height: 50upx;
	align-items: center;
	border-radius: 25rpx;
	text {
		font-size: 20upx;
		color: #6b6b6b;
		font-weight: normal;
	}
	.iconfont {
		color: #666666;
		font-size: 44upx;
		margin-right: 6upx;
	}
	.red {
		color: #fe305b;
	}
}
</style>
